public class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode headler1 = l1;
        ListNode headler2 = l2;
        ListNode head = null;
        ListNode lastListNode = null;
        int val0 = 0;
        while (headler1 != null || headler2 != null) {
            int val1 = headler1 == null ? 0 : headler1.val;
            int val2 = headler2 == null ? 0 : headler2.val;
            int sum = val1 + val2 + val0;
            ListNode present = null;
            if (sum >= 10) {
                val0 = sum / 10;
                present = new ListNode(sum % 10);
            } else {
                val0 = 0;
                present = new ListNode(sum);
            }
            if (head == null) {
                head = present;
            } else {
                lastListNode.next = present;
            }
            lastListNode = present;
            headler1 = headler1 == null ? null : headler1.next;
            headler2 = headler2 == null ? null : headler2.next;
        }
        if (val0 > 0) lastListNode.next = new ListNode(1);
        return head;
    }
}
